Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
How do I split a string between / and "+" based on an outgoing link click, when there are colons in the actual URL?

JS Beginner here. I need to return itemName from a URL string, however, there are colons in the URL itself. When I split using ("""), I get an error that this won't work.

I have gotten this far, but I don't know what to change in my function to get the desired result. See the examples below:

Below is the URL:

 "https://www.website.com/items/item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2" 

Below you can see my code.

  
   if ({{Outgoing link}})
  var itemName= {{Click URL}};
      return itemName.split("/")[5].split(".")[0];
   
    
    console.log(extractSliceFromUrl(itemName))

   } 

This is my expected result:

 "item-name-1"

This is the actual result I get:

 "item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2"
 
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Would the following work?

It extracts whatever's between the last / and the first "+".

const url = "\"https://www.website.com/items/item-name-1\"+\"?date_1=2022-10-05&date_2=2022-10-07&amount=2\"";
console.log(url.substring(url.lastIndexOf('/') + 1, url.indexOf('"+"')));

about 4 years ago · Juan Pablo Isaza Denunciar

0

I'd split by ? first:

const theURL = "https://www.website.com/items/item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2";

theURL.split("?")[0].split("/")[5].split(".")[0];

about 4 years ago · Juan Pablo Isaza Denunciar

0

With the secondary result, you could just remove the ending using:

'"item-name-1"+"?date_1=2022-10-05&date_2=2022-10-07&amount=2"'.replace(/("[^"]+?")\+/, '$1')

Explanation of /("[^"]+?")\+/ (RegExp)

  • (...) catch the pattern (becomes the $1)
  • [^"] everything not "
  • +? get the shortest result possible
  • \+ escape + (+ is a special symbol, this will treat it as plain text)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda